package com.fan.shop.services;

import java.util.List;

import javax.inject.Inject;
import javax.inject.Named;

import org.springframework.transaction.annotation.Transactional;

import com.fan.shop.dao.LocationDao;
import com.fan.shop.domain.Location;

@Named("locationService")
@Transactional(readOnly = true)
public class LocationServiceImpl implements LocationService {

	@Inject
	@Named("locationDao")
	private LocationDao locationDao;

	public Location getLocation(int id) {
		Location location = locationDao.getLocation(id);
		return location;
	}

	public List<Location> getAllLocations() {
		List<Location> list = locationDao.getAllLocations();
		return list;
	}

	public int getSize() {
		return locationDao.getSize();
	}

	@Transactional(readOnly = false)
	public void addLocation(Location location) {
		locationDao.addLocation(location);
	}

	@Transactional(readOnly = false)
	public void updateLocation(Location location) {
		locationDao.updateLocation(location);
	}

	@Transactional(readOnly = false)
	public void deleteLocation(Location location) {
		locationDao.deleteLocation(location);
	}

	public boolean hasLocation(int id) {
		return locationDao.hasLocation(id);
	}

	@SuppressWarnings("rawtypes")
	public List getList() {
		return getAllLocations();
	}

	public List<String> getColumnNames() {
		return locationDao.getColumnNames();
	}

	public int getColumnsSize() {
		return getColumnNames().size();
	}

	public boolean exists(Location location) {
		for (Location lc : getAllLocations()) {
			if (lc.getCity().equals(location.getCity())
					&& lc.getState().equals(location.getState())
					&& lc.getCountry().equals(location.getCountry())) {
				return true;
			}
		}
		return false;
	}

	public Object copy(Object obj) {
		// TODO Auto-generated method stub
		return null;
	}

	public Location getLocationByValue(String value) {
		return locationDao.getLocationByValue(value);
	}

}
